﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HZ.Supervise.Web.Secondphase
{
    public partial class ReportFriststLevelBasicMedicine : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Databind();
            }
        }
        public void Databind()
        {
            DataTable dt = new DataTable();
            DataColumn dc0 = new DataColumn("MedicineName", typeof(string)); dt.Columns.Add(dc0);
            DataColumn dc1 = new DataColumn("Type", typeof(string)); dt.Columns.Add(dc1);
            DataColumn dc2 = new DataColumn("InMoney", typeof(string)); dt.Columns.Add(dc2);
            DataColumn dc3 = new DataColumn("InNumber", typeof(string)); dt.Columns.Add(dc3);
            DataColumn dc4 = new DataColumn("InPercent", typeof(string)); dt.Columns.Add(dc4);
            DataColumn dc5 = new DataColumn("SotckMoney", typeof(string)); dt.Columns.Add(dc5);
            DataColumn dc6 = new DataColumn("StockNumber", typeof(string)); dt.Columns.Add(dc6);
            DataColumn dc7 = new DataColumn("StockPercent", typeof(string)); dt.Columns.Add(dc7);
            DataColumn dc8 = new DataColumn("Profit", typeof(string)); dt.Columns.Add(dc8);

            DataRow dr = dt.NewRow();
            dr[0] = "一月";
            dr[1] = "基药";
            dr[2] = "1000";
            dr[3] = "30";
            dr[4] = "60%";
            dr[5] = "900";
            dr[6] = "20";
            dr[7] = "50%";
            dr[8] = "12";
            dt.Rows.Add(dr);

            DataRow dr1 = dt.NewRow();
            dr1[0] = "二月";
            dr1[1] = "非基药";
            dr1[2] = "1000";
            dr1[3] = "30";
            dr1[4] = "60%";
            dr1[5] = "900";
            dr1[6] = "20";
            dr1[7] = "50%";
            dr1[8] = "12";
            dt.Rows.Add(dr1);

            DataRow dr2 = dt.NewRow();
            dr2[0] = "三月";
            dr2[1] = "基药";
            dr2[2] = "1000";
            dr2[3] = "30";
            dr2[4] = "60%";
            dr2[5] = "900";
            dr2[6] = "20";
            dr2[7] = "50%";
            dr2[8] = "12";
            dt.Rows.Add(dr2);

            DataRow dr3 = dt.NewRow();
            dr3[0] = "四月";
            dr3[1] = "非基药";
            dr3[2] = "1000";
            dr3[3] = "30";
            dr3[4] = "60%";
            dr3[5] = "900";
            dr3[6] = "20";
            dr3[7] = "50%";
            dr3[8] = "12";
            dt.Rows.Add(dr3);

            #region aaa
            DataTable dtSoure = new DataTable();
            dtSoure = dt.Clone();
            for (int i = 0; i < dt.Rows.Count;i++ )
            {
                if (i < (dt.Rows.Count - 1))
                {
                    if (dt.Rows[i][0].ToString().Trim() == dt.Rows[i + 1][0].ToString().Trim())
                    {
                        DataRow drOne = dt.Rows[i];
                        DataRow drTwo = dt.Rows[i + 1];
                        dtSoure.Rows.Add(drOne.ItemArray);
                        dtSoure.Rows.Add(drTwo.ItemArray);
                        i++;

                    }
                    else
                    {
                       
                        DataRow drOld = dtSoure.NewRow();
                        drOld.ItemArray = dt.Rows[i].ItemArray;

                        DataRow drNew = dtSoure.NewRow();
                        drNew.ItemArray = dt.Rows[i].ItemArray;
                      
                        if (drNew[1].ToString().Trim() == "基药")
                        {
                            drNew[1] = "非基药";
                            drNew[2] = "";
                            drNew[3] = "";
                            drNew[4] = "";
                            drNew[5] = "";
                            drNew[6] = "";
                            drNew[7] = "";
                            drNew[8] = "";                           
                            dtSoure.Rows.Add(drOld.ItemArray);
                            dtSoure.Rows.Add(drNew.ItemArray);

                        }
                        else
                        {
                            drNew[1] = "基药";
                            drNew[2] = "";
                            drNew[3] = "";
                            drNew[4] = "";
                            drNew[5] = "";
                            drNew[6] = "";
                            drNew[7] = "";
                            drNew[8] = "";                            
                            dtSoure.Rows.Add(drNew.ItemArray);
                            dtSoure.Rows.Add(drOld.ItemArray);
                            
                        }
                    }
                }
                else
                {
                    if (dt.Rows[i][0].ToString().Trim() == dt.Rows[i - 1][0].ToString().Trim())
                    {
                        continue;
                    }
                    else
                    {
                       
                        DataRow drOld = dtSoure.NewRow();
                        drOld.ItemArray = dt.Rows[i].ItemArray;

                        DataRow drNew = dtSoure.NewRow();
                        drNew.ItemArray = dt.Rows[i].ItemArray;

                        if (drNew[1].ToString().Trim() == "基药")
                        {
                            drNew[1] = "非基药";
                            drNew[2] = "";
                            drNew[3] = "";
                            drNew[4] = "";
                            drNew[5] = "";
                            drNew[6] = "";
                            drNew[7] = "";
                            drNew[8] = "";                            
                            dtSoure.Rows.Add(drOld.ItemArray);
                            dtSoure.Rows.Add(drNew.ItemArray);

                        }
                        else
                        {
                            drNew[1] = "基药";
                            drNew[2] = "";
                            drNew[3] = "";
                            drNew[4] = "";
                            drNew[5] = "";
                            drNew[6] = "";
                            drNew[7] = "";
                            drNew[8] = "";
                            dtSoure.Rows.Add(drNew.ItemArray);//非基药在前
                            dtSoure.Rows.Add(drOld.ItemArray);

                        }
                    }
                }

            }
            #endregion
            gvwProcureCatalog.DataSource = dtSoure;

            gvwProcureCatalog.DataBind();
            for (int j = 0; j < gvwProcureCatalog.Rows.Count; j++)
            {
                //名称相同才能合并
                //防止超出索引
                if (j < (gvwProcureCatalog.Rows.Count - 1))
                {
                    if (gvwProcureCatalog.Rows[j].Cells[0].Text.Trim() == gvwProcureCatalog.Rows[j + 1].Cells[0].Text.Trim())
                    {
                        gvwProcureCatalog.Rows[j].Cells[0].RowSpan = 2;
                        gvwProcureCatalog.Rows[j + 1].Cells[0].Visible = false;

                        gvwProcureCatalog.Rows[j].Cells[9].RowSpan = 2;
                        gvwProcureCatalog.Rows[j + 1].Cells[9].Visible = false;
                        j++;
                    }
                    else
                    {
                        
                    }
                }
              
            }
        }
        protected void gvwProcureCatalog_RowCreated(object sender, GridViewRowEventArgs e)
        {
            //    switch (e.Row.RowType)
            //    {
            //        case DataControlRowType.Header:

            //            //取得下拉框的月份


            //            //第一行表头
            //            TableCellCollection tcHeader = e.Row.Cells;
            //            tcHeader.Clear();
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[0].Attributes.Add("colspan", "1"); //跨Row
            //            tcHeader[0].Attributes.Add("bgcolor", "LightSteelBlue");
            //            //tcHeader[0].Attributes.Add("bgcolor", "white");
            //            tcHeader[0].Text = "";
            //            //tcHeader.Add(new TableHeaderCell());
            //            //tcHeader[1].Attributes.Add("bgcolor", "Red");
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[1].Attributes.Add("colspan", "4"); //跨Column
            //            tcHeader[1].Text = "1月";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[2].Attributes.Add("colspan", "4"); //跨Column
            //            tcHeader[2].Text = "2月";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[3].Attributes.Add("colspan", "2"); //跨Column
            //            tcHeader[3].Text = "</th></tr><tr>";



            //            //第2行表头
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[4].Attributes.Add("bgcolor", "LightSteelBlue");
            //            tcHeader[4].Text = "";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[5].Attributes.Add("bgcolor", "LightSteelBlue");
            //            tcHeader[5].Attributes.Add("colspan", "2");
            //            tcHeader[5].Text = "配送总金额【11111】";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[6].Attributes.Add("bgcolor", "LightSteelBlue");
            //            tcHeader[6].Attributes.Add("colspan", "2");
            //            tcHeader[6].Text = "配送总数量【30】";

            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[7].Attributes.Add("bgcolor", "LightSteelBlue");
            //            tcHeader[7].Attributes.Add("colspan", "2");
            //            tcHeader[7].Text = "配送总金额【222222】";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[8].Attributes.Add("bgcolor", "LightSteelBlue");
            //            tcHeader[8].Attributes.Add("colspan", "2");
            //            tcHeader[8].Text = "配送总数量【40】";

            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[9].Attributes.Add("bgcolor", "LightSteelBlue");
            //            tcHeader[9].Attributes.Add("colspan", "2");
            //            tcHeader[9].Text = "</th></tr><tr>";

            //            //第3行表头
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[10].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[10].Text = "生产企业";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[11].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[11].Text = "基药总金额";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[12].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[12].Text = "非基药总金额";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[13].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[13].Text = "基药总数量";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[14].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[14].Text = "非基药总数量";

            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[15].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[15].Text = "基药总金额";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[16].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[16].Text = "非基药总金额";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[17].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[17].Text = "基药总数量";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[18].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[18].Text = "非基药总数量";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[19].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[19].Text = "操作";
            //            tcHeader.Add(new TableHeaderCell());
            //            tcHeader[20].Attributes.Add("bgcolor", "Khaki");
            //            tcHeader[20].Text = "图表</th></tr><tr>";
            //            break;
            //    }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            Databind();
        }

        protected void lbnSwitch_Click(object sender, EventArgs e)
        {

        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {

        }
        protected void lbtnSee_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 行绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwProcureCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //gvwProcureCatalog.Rows[0].Cells[0].RowSpan = 2;
            //if (e.Row.RowIndex == 0)
            //{
            //    strText = e.Row.Cells[0].Text;
            //}
            //if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != 0)
            //{
            //    if (e.Row.Cells[0].Text == strText)
            //    {
            //        intRowSpan++;
            //        grvEX.Rows[intIndex].Cells[0].RowSpan = intRowSpan;
            //        e.Row.Cells[0].Visible = false;
            //    }
            //    else
            //    {
            //        intRowSpan = 1;
            //        intIndex = e.Row.RowIndex;
            //    }
            //    strText = e.Row.Cells[0].Text;
            //}
        }
    }
}
